home *** CD-ROM | disk | FTP | other *** search
- /* Unpack a single file packed by "sunpack" into a set of files whose names are provided by
- in-line keys at the biginning of each file */
- /* It read from standard input, output is automatically directed to
- the right directories with the properly assigned file names */
- /* Do not check for the existence or permission of files */
-
- #include <stdio.h>
- #define FALSE 1
- #define TRUE 0
- #define LINE_LEN 240
-
- main()
- {
- int c,write_on;
- char key[4],s[LINE_LEN],file[80];
- FILE *fp,*fopen();
-
- write_on = FALSE;
- while ( ((int) getline(s,LINE_LEN)) != EOF) {
- if(strncmp(s,"/*KTAR",6)==0){
- if(strncmp(s,"/*KTAR NEWFILE",14)==0){
- get_file_name(file,s,15);
- fp=fopen(file,"w");
- if(fp==NULL){
- printf("File %s not found!\n",file);
- write_on = FALSE;
- }
- else
- write_on = TRUE;
- }
- else if(strncmp(s,"/*KTAR ENDFILE",14)==0){
- fclose(fp);
- write_on = FALSE;
- }
- else {
- if(write_on == TRUE)
- fputs(s,fp);
- }
- }
- else {
- if(write_on == TRUE)
- fputs(s,fp);
- }
- }
- }
-
- /* get file name starting starting at n'th character of s until white space */
- get_file_name(t,s,n)
- char t[],s[];
- int n;
- {
- int i =0;
-
- while (s[n] != ' ' && s[n] != '\n' && s[n] != '\t' && s[n] != '\0')
- t[i++] = s[n++];
- t[i]='\0';
- }
-
- /* get line into s, return length */
-
- int
- getline(s,length)
- char s[];
- int length;
- {
- int c,i;
-
- i = 0;
- while (--length > 0 && (c=getchar()) != EOF && c != '\n')
- s[i++] = c;
- if( c == '\n')
- s[i++] = c;
- s[i] = '\0';
- if(c == EOF)
- return(c);
- else
- return(i);
- }
-